/** \file
* Definition of the Twitter status database class.
* This file is part of Chorus, available at
* http://code.google.com/p/chorus-twitter/ . This file and all associated files
* and derivative works are bound by the terms of the LGPL 3.0 license,
* available at http://www.gnu.org/licenses/lgpl-3.0-standalone.html .
* \par Subversion URL:
* \$URL: http://chorus-twitter.googlecode.com/svn/branches/cpp/src/twitter/StatusTree.hpp $
* \version \$Rev: 153 $
* \date    \$Date: 2010-04-06 07:43:42 +0000 (Tue, 06 Apr 2010) $
*/

#pragma once

#include "xml/DefaultTree.hpp"
#include "twitter/TwitterStatus.hpp"

// Predeclare the user tree.
class UserTree;

/// The Twitter status database.
class StatusTree :
	public DefaultTree,
	public TypedXmlTree<TwitterStatus>
{
public:
	/// The constructor.
	/// \param curlGlobInit The curl globals pointer.
	StatusTree(CurlGlob *curlGlobInit);

	/// The destructor.
	virtual ~StatusTree();

public:
	/// Set the user database.
	/// \param usersInit A pointer to the users database.
	void setUserTree(UserTree *usersInit);

	/// The XML/SAX handler for element start.
	/// \param name  The name of the element.
	/// \param attrs The list of attributes, alternating between name and value
	///              and ending with a null.
	virtual void startElement(const xmlChar *name, const xmlChar **attrs);

	/// The XML/SAX handler for element end.
	/// \param name  The name of the element.
	virtual void endElement(const xmlChar *name);

	/// The XML/SAX handler for element inner text.
	/// \param ch  The element's inner text.
	/// \param len The length of the element's inner text.
	virtual void elementText(const xmlChar *ch, unsigned len);

	/// Get the file path for this database.
	/// \return The file path string.
	virtual const char *getFilePath() const
	{
		return "statuses.xml";
	}

	/// Get the URL path for this database.
	/// \return The URL path string.
	virtual const char *getUrlPath() const
	{
		return "http://twitter.com/statuses/friends_timeline.xml";
	}

	/// Get the element tag for this tree type.
	/// \return The element tag string.
	virtual const xmlChar *getElementTag() const
	{
		return (const xmlChar*)"status";
	}

private:
	/// A pointer to the users database.
	UserTree *users;

	/// Whether we're currently parsing a user subtag.
	bool parsingUser;
};
